package priv.demo5.d94.main;

import org.w3c.dom.Document;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import java.io.File;

public class Main1 {

    public static void main(String[] args) throws Exception {

        File source = new File(Main1.class.getClassLoader().getResource("file/demo.xml").getFile());

        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document sourceDoc = builder.parse(source);

        File styleSheet = new File(Main1.class.getClassLoader().getResource("file/demoXsl.xml").getFile());
        StreamSource styleSource = new StreamSource(styleSheet);
        Transformer t = TransformerFactory.newInstance().newTransformer(styleSource);
        t.setOutputProperty(OutputKeys.INDENT, "no");
        t.setOutputProperty(OutputKeys.METHOD, "html");
        t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","5");

        t.transform(new DOMSource(sourceDoc), new StreamResult(System.out));
    }
}